﻿<cfsilent>
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		
		depId = sessionAdvice.getUserProp("teacherDepartment");
		
		termId = event.getArg("TID");
		courseId = event.getArg("CID");
		subjectId = event.getArg('SubID');
		

		sql = "	SELECT
					c.cid,c.course_name
				FROM
					t_course c
				WHERE
					c.cid = :courseId ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		
		queryObj.addParam( name="courseId", value=courseId, cfsqltype="cf_sql_varchar" );

        rs_courseEntity = queryObj.execute( sql=sql ).getResult();
		
		

		sql = "	SELECT
					s.sbj_id,s.sbj_short
				FROM
					t_subject s
				WHERE
					s.sbj_id = :subjectId ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		
		queryObj.addParam( name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar" );

        rs_subjectEntity = queryObj.execute( sql=sql ).getResult();
		
		
		event.setArg("pageTitle", "教学运行基础数据 - 教学计划 - 计划课程授课班级");
	
		if ( len(termId) and len(courseId) ) {
			
			sql = "	SELECT
						p.p_id,
						clz.cls_name,
						clz.grade,
						p.cidx,
						tc.campus_name,
						clz.cls_size,
						clz.cls_scale,
						s.sbj_short,
						cn.cna_name,
						cp.prop_name,
						s.institute_id
					FROM
						t_plan p
						INNER JOIN t_class clz ON clz.cls_id = p.cls_id
						INNER JOIN t_campus tc ON tc.campus_id = clz.campus_id
						INNER JOIN t_subject s ON s.sbj_id = clz.sbj_id
						INNER JOIN t_course_nature cn ON cn.cna_id = p.cna_id
						INNER JOIN t_course_prop cp ON cp.prop_id = p.prop_id
					WHERE
						p.term_id = :term 
						AND
						p.cid = :course 
					ORDER BY
						s.institute_id,clz.cls_name";
			
			queryObj = new Query( datasource=application.dnsSlave );
		
			queryObj.addParam( name="term", value=termId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="course", value=courseId, cfsqltype="cf_sql_varchar" );

       		rs_clazz = queryObj.execute( sql=sql ).getResult();
			
		}
		
		passArgs = structNew();
		
		structInsert(passArgs, "SubID", rs_subjectEntity.sbj_id, true);
		
		if ( rs_clazz.recordCount ) {
			structInsert(passArgs, "Grade", rs_clazz['grade'][1], true);
		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('planSchemaBySubject', passArgs)#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText"><cfoutput>#rs_subjectEntity.sbj_short#</cfoutput>专业学期开课计划</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 info"></i><cfoutput>#rs_courseEntity.course_name#</cfoutput>
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="tabContentBox">
					
					<div class="noticeBlock">
						<h3>课程开课班级计划</h3>
						<p><p><span class="img icon16x16 message"></span>下列是在当前学期根据授课计划要性质该课程任务的班级</p>
						<hr/>
					</div>
					
					<cfif rs_clazz.recordCount>
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td width="50">校区</td>
									<td width="30">年级</td>
									<td width="60">专业</td>
									<td>行政班</td>
									<td width="48">是否执行</td>
									<td width="48">类别</td>
									<td width="48">课程性质</td>
									<td width="48">计划人数</td>
									<td width="48">实际人数</td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_clazz">
									<cfset row++ />
									<tr class="editRows" rowid="<cfoutput>#rs_clazz.p_id#</cfoutput>">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_clazz.campus_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_clazz.grade#</cfoutput></span></td>
										<td><cfoutput>#rs_clazz.sbj_short#</cfoutput></td>
										<td><cfoutput>#rs_clazz.cls_name#</cfoutput></td>
										<td>
											<cfif rs_clazz.institute_id eq depId>
												<a rowid="<cfoutput>#rs_clazz.p_id#</cfoutput>" usage="ForCourse" class="stat <cfif rs_clazz.cidx eq "XXX">no<cfelse>yes</cfif>"></a>
												<cfelse>
												<span class="stat locked"></span>
											</cfif>
										</td>
										<td><cfoutput>#rs_clazz.cna_name#</cfoutput></td>
										<td><cfoutput>#rs_clazz.prop_name#</cfoutput></td>
										<td align="right"><span class="numeric"><cfoutput>#rs_clazz.cls_size#</cfoutput></span></td>
										<td align="right"><span class="numeric"><cfoutput>#rs_clazz.cls_scale#</cfoutput></span></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
					</cfif>

					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
							
							/* isCourseArrange trigger */
							$("a[usage]").click(function(){
								
								var rowid = $(this).attr("rowid");
								var method = $(this).attr("usage");
							
								var status = $(this).hasClass("yes");
								var newStatus = true;
								
								/* 切换状态数据 */
								if (status) {
									newStatus = false;
								}
								
								/* 发送请求 */
								$(this).removeClass("no").removeClass("yes").addClass("waiting");
								
								$.post(
										"<cfoutput>#buildURL('apiPlanSchemaClassPropChange')#</cfoutput>", 
										{
											'pid' : rowid,
											'prop' : method,
											'status' : newStatus,
											'seed': (new Date()).getTime()
										}, 
										function(data) {

											var result = jQuery.parseJSON(data);
											
											var $trigger = $("a[usage][rowid='" + result.PlanID + "']")
											
											$trigger.removeClass("waiting");
											
											/* 刷新是否排课状态数据 */
											if (result.CourseIndex == "XXX") {
												$trigger.addClass("no");
											}
											else {
												$trigger.addClass("yes");
											}
										});
							});
							
						});
						// -->
						//]]>
					</script>
					
				</div>
			</div>
		</li>
	</ul>
</div>

